<?php 
session_start();
class contact extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       private $_configs = null;
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('javascript');
            $this->load->library('session');
            $this->load->library('smarty3','','smarty');
            $this->_configs["title"]="Authority Management";
            $this->_configs["authority"]="contact";
            $this->_configs["MinAuthority"]=1;
            $this->load->model('admin-planners/contact_model','contact_model');
            if($this->checkauthority()<1){AccessDenied();}
        }
        public function index()
	{
            $this->smarty->assign('_SESSION', $_SESSION);
            $configs["title"]="Contact Management";
            $this->smarty->assign('configs', $this->_configs);
            $this->smarty->view('admin-planners/contact/01_contact','contentofview');
            $this->smarty->view('admin-planners/00_1_styles','styles');
            $this->smarty->view('admin-planners/00_2_scripts','scripts');
            $this->smarty->view('admin-planners/00_3_menus','menus');
            $this->smarty->view('admin-planners/10_template','view');
            $this->smarty->display('admin-planners/01_manage');
	}
        public function checkauthority(){
            if(isset($_SESSION["ADP-USER"]["AUTHORITY"])){
                $myau=-1;
                if(is_array($_SESSION["ADP-USER"]["AUTHORITY"])){
                    foreach ($_SESSION["ADP-USER"]["AUTHORITY"] as $au){
                        if($au["keyword"]=="view" && $myau==-1)$myau=0;
                        if($au["keyword"]=="admin")$myau=1;
                        if($au["keyword"]==$this->_configs["authority"]){
                            if($au["value"]==0 && $myau==-1) $myau=0;
                            if($au["value"]==1) $myau=1;
                        }
                    }
                }
                return $myau>=$this->_configs["MinAuthority"]?$myau:-1;
            }return -1;
        }
        function detail($id=""){
            //$id=$_POST["id"];
            $result=$this->contact_model->get($id);
            $this->smarty->assign('contactobj', objectToArray($result[0]));
            $this->smarty->display('admin-planners/contact/02_contact_detail');
        }
        function jqgrid_data(){
            $authoritys=array();
            $result['total_rows']=0;
            if($this->checkauthority()>=0){
                $result=$this->contact_model->gettotal_rows();
                $rows=$result['rows'];
                // get data and store in a json array
                foreach ($rows as $row) {
                    $authoritys[] = array(
                            //'_id_'       => $row->id,
                            '_Name_'     => $row->Name,
                            '_Phone_'    => $row->Phone,
                            '_Email_'     => $row->Email,
                            '_Address_'   => $row->Address,
                            '_Product_'   => $row->Product,
                            '_Amount_'   => $row->Amount,
                            '_Date_'   => $row->Date,
                            '_Insert_'   => $row->Insert,
                            '_Contact_'   => json_encode(array(
                                            "_ContactID_"=>$row->ContactID,
                                            "_Delete_"=>$row->Delete
                                            
                                        ))
                    );
                }
            }
            $data[] = array(
                'TotalRows' => $result['total_rows'],
                'Rows' => $authoritys
            );
            echo json_encode($data);
        }
        
        
        
       
        
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */